package xyz.ljcc.ccmt.handler.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import xyz.ljcc.ccmt.model.base.Dept;
import xyz.ljcc.ccmt.model.result.ResultModel;
import xyz.ljcc.ccmt.service.api.admin.DeptService;

/**
 * 科室请求头部分
 * @author liucan
 *
 */
@RequestMapping("/admin/dept")
@RestController
public class DeptHandler {

	@Autowired
	private DeptService deptService;
	
	@RequestMapping(value="loadDeptList",method=RequestMethod.POST)
	public ResultModel loadDeptList(String deptName) {
		List<Dept> deptDicts = deptService.getDepts(deptName);
		return new ResultModel(true, deptDicts, "获取科室列表成功");
	}
	
	/**
	 * 新增
	 * @param deptDict
	 * @return
	 */
	@RequestMapping(method=RequestMethod.POST)
	public ResultModel saveDeptDict(Dept Dept) {
		deptService.saveDept(Dept);
		return new ResultModel(true, null, "保存成功");
	}
	
	/**
	 * 编辑
	 * @param deptDict
	 * @return
	 */
	@RequestMapping(method=RequestMethod.PUT)
	public ResultModel editDeptDict(Dept deptDict) {
		deptService.editDept(deptDict);
		return new ResultModel(true, null, "更新成功");
	}
	
	/**
	 * 删除
	 * @param deptDict
	 * @return
	 */
	@RequestMapping(method=RequestMethod.DELETE,value="/{id}")
	public ResultModel delDeptDict(@PathVariable(value="id") Integer id) {
		deptService.delDept(id);
		return new ResultModel(true, null, "删除成功");
	}
	
	/**
	 * 查询单条记录
	 * @param deptDict
	 * @return
	 */
	@RequestMapping(method=RequestMethod.GET,value="/{id}")
	public ResultModel getDeptDict(@PathVariable(value="id") Integer id) {
		Dept deptDict = deptService.getDeptById(id);
		return new ResultModel(true, deptDict, "查询成功");
	}
	
	/**
	 * 状态更新
	 * @param id
	 * @param active
	 * @return
	 */
	@RequestMapping(method=RequestMethod.POST,value="/active")
	public ResultModel activeDept(Integer id,Integer active) {
		deptService.activeDept(id, active);
		return new ResultModel(true, null, active == 1 ? "启用成功" : "停用成功");
	}
}
